<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>最长等差数列</title>
</head>
<body>
  <script>
    function fn(A) {
      let len = A.length
      let dp = new Array(len).fill(0).map(() => new Array(len).fill(2))
      let max = 2
      for (let i = 0; i < len; i++) {
        for (let j = i + 1; j < len; j++) {
          for (let k = 0; k < i; k++) {
            if (A[j] - A[i] === A[i] - A[k]) {

              dp[i][j] = dp[k][i] + 1
              max = Math.max(dp[i][j], max)
            }
          }
        }
      }
      return max
    }
    console.log(fn([3, 6, 9, 12]))
  </script>
</body>
</html>